package chapter;

public class DynamicArray {
	
	Object[] objects;
	int size=10;
	int index = -1;
	float pre = .2f;
	
	
	public DynamicArray(){
		objects = new Object[size];
	}
	
	public void init(){
		for(int i=0;i<10;i++){
			index++;
			objects[i]=i;
		}
	}
	
	public void add(Object obj){
		index++;
		if(index < size){
			objects[index]=obj;
		}else {
			size += pre*size;
			
			Object[] temp = new Object[size];
			
			System.arraycopy(objects, 0, temp, 0, objects.length);
			temp[index]=obj;
			objects = temp;
			
		}
	}
	
	public void printAll(){
		for(int i=0;i<objects.length;i++ ){
			System.out.println(objects[i]);
		}

	}
	

	public static void main(String[] args) {
		DynamicArray da = new DynamicArray();
		da.init();
		da.add(100);
		da.printAll();

	}

}
